package ua.pp.bizon.yandex.uploader.atom;

import org.apache.abdera.model.Element;
import org.apache.commons.logging.LogFactory;

public class AppLink {

	private Element e;
	private String url;

	public AppLink() {
	}

	public AppLink(Element e) {
		this.e = e;
	}

	public AppLink(String url) {
		this.url = url;
	}

	public String getId() {
		return e.getAttributeValue("id");
	}

	public String getLink() {
		if (url == null){
			url= e.getAttributeValue("href");
		}
		return url;
	}
	
	public String getRel() {
		String rel = e.getAttributeValue("rel");
		return rel;
	}

	public String getName() {
		return e.getElements().size() > 0 ? e.getElements().get(0).getText() : "";
	}


	@Override
	public String toString() {
		return "AppLink [id=" + getId() + ", link=" + getLink() + ", name=" + getName()
				+ ", element=" + e + "]";
	}

	public void setElement(Element element) {
		this.e = element;
	}

	public Element getElement() {
		return e;
	}

	public void setLink(String correctLink) {
		LogFactory.getLog(getClass()).debug(getLink() + " has been changed to " + correctLink);
		url = correctLink;
		e.setAttributeValue("href", correctLink);
		
	}

}
